from django.contrib import admin
from django.conf import settings
import tsl_backend.frontend_api.models.route as routes
import tsl_backend.frontend_api.models.order_routing as order_routing
import tsl_backend.frontend_api.models.workorder as workorders

# Register your models here.


class StoneMountSettingAdmin(admin.ModelAdmin):
    list_display = ["code", "name"]
    search_fields = ["code", "name"]
admin.site.register(routes.StoneMountSetting, StoneMountSettingAdmin)


class QcFailedReasonAdmin(admin.ModelAdmin):
    list_display = ["reason", "unit", "get_flow_name", "get_role_names"]
    # search_fields = ["code", "name"]

    def get_flow_name(self, obj):
        return obj.flow
    
    
    def get_role_names(self, obj):
        return ", ".join(obj.role.values_list("chinese_name", flat=True))
    
    get_flow_name.short_description="流程"
    get_role_names.short_description="角色"

admin.site.register(order_routing.QcFailedReason, QcFailedReasonAdmin)



class ProductionRemarkAdmin(admin.ModelAdmin):
    list_display = ["type", "remark"]
    search_fields = ["type", "remark"]
    
admin.site.register(order_routing.ProductionRemark, ProductionRemarkAdmin)

if settings.DEBUG:
    admin.site.register(workorders.Detail)
    admin.site.register(workorders.ProductionActualBOM)
    admin.site.register(workorders.ProductionStandardBOM)
    admin.site.register(routes.Master)
    admin.site.register(routes.OutstandingMaster)
    admin.site.register(routes.RouteFlows)
    # admin.site.register(routes.Standard)
    admin.site.register(order_routing.OrderRouting)
    admin.site.register(order_routing.RouteDetail)
    admin.site.register(order_routing.Record)
    admin.site.register(order_routing.WorkerRecord)
    admin.site.register(order_routing.CheckRecord)
    admin.site.register(order_routing.WorkerActionRecord)
    admin.site.register(order_routing.ProductionRemarkAns)
    admin.site.register(order_routing.QcFailed)
    admin.site.register(order_routing.Dispatcher)
    admin.site.register(routes.Difficulty)
    
